using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using static UnityEngine.EventSystems.EventTrigger;

public delegate void CallbackWhatToDoDropDown(WhatToDoDropDown dropdown);
public delegate void CallbackWhatToDoDropDown_Int(WhatToDoDropDown dropdown, int value);
public class WhatToDoDropDown : MonoBehaviour
{
    ShipEventTrigger m_Trigger;
    public CallbackWhatToDoDropDown m_OnSelectedCallback;
    public CallbackWhatToDoDropDown_Int m_OnValueChangedCallback;
    void Start()
    {

        GetComponent<Dropdown>().onValueChanged.AddListener(OnValueChanged);
        var eventTrigger = gameObject.AddComponent<EventTrigger>();
        Entry pointEnter = new Entry();
        pointEnter.eventID = EventTriggerType.PointerEnter;
        pointEnter.callback.AddListener(OnPointEnter);
        eventTrigger.triggers.Add(pointEnter);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    public void SetTrigger(ShipEventTrigger trigger)
    {
        m_Trigger = trigger;
        if((int)m_Trigger.m_TriggerType != GetComponent<Dropdown>().value)
            GetComponent<Dropdown>().value = (int)m_Trigger.m_TriggerType;
    }
    public ShipEventTrigger GetTrigger()
    {
        return m_Trigger;
    }
    void OnPointEnter(BaseEventData eventData)
    {
        if(m_OnSelectedCallback != null)
        {
            m_OnSelectedCallback(this);
        }
    }
    void OnValueChanged(int value)
    {
        if (m_OnValueChangedCallback != null)
            m_OnValueChangedCallback(this, value);
    }
}
